package main

import "fmt"

type Writer interface {
	Writer([]byte) (int, error)
}

type MyFile struct {
}

func (f *MyFile) Writer() {

}

type MyFile2 struct {
}

func (f *MyFile2) Writer(ctx []byte) (int, error) {
	return 0, nil
}

type Myfile3 struct {
}

func (f Myfile3) Writer(ctx []byte) (int, error) {
	return 0, nil
}

func main() {
	var writer Writer
	fmt.Printf("%T,%#v\n", writer, writer)

	// MyFile 无Writer方法，返回值参数与接口不一致
	// var myfile MyFile
	// writer = myfile
	// fmt.Printf("%T,%#v\n", writer, writer)

	// MyFile2 方法接收者为指针（f *MyFile2），需要定义为指针接收
	var myfile2Pointer = new(MyFile2)
	writer = myfile2Pointer
	fmt.Printf("%T,%#v\n", writer, writer)

	// MyFile2 方法接收者为值（f MyFile2），可以定义值变量来接收也可定义指针来接收
	var myfile3 Myfile3
	writer = myfile3
	fmt.Printf("%T,%#v\n", writer, writer)

	var myfile3Pointer = new(Myfile3)
	writer = myfile3Pointer
	fmt.Printf("%T,%#v\n", writer, writer)
}
